import startServer from 'quickly-deploy'
import path from 'path'
import { fileURLToPath } from 'url'
import bodyParser from "koa-bodyparser"
import compress from "koa-compress"
import router from "./api.middleware.js"

const __dirname = path.dirname(fileURLToPath(import.meta.url))
// env path
const envPath = path.resolve(__dirname, './.env')

const app = startServer([path.resolve(__dirname, '../docs/.vitepress/dist')], envPath, [], [
  bodyParser({ jsonLimit: '10kb' }),
  router(/\/api\/.+/),
  compress({
    threshold: 1024 //数据超过1kb时压缩
  }),
  async (ctx, next) => {
    // 配置浏览器缓存：设置缓存控制头，max-age为缓存时间，单位为秒，不频繁更新默认为一年
    ctx.set('Cache-Control', 'max-age=31536000');
    await next();
  }
])
// start server
app.start()
